package com.sxkf.template.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxkf.template.entity.User;
import com.sxkf.template.entity.UserDetails;
import com.sxkf.template.mapper.UserDetailsMapper;
import com.sxkf.template.mapper.UserMapper;
import com.sxkf.template.service.UserDetailsService;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.faceid.v20180301.models.IdCardVerificationRequest;
import com.tencentcloudapi.faceid.v20180301.models.IdCardVerificationResponse;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.exception.SxkfException;
import org.jeecg.common.util.CheckEmptyUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张广成
 * @since 2024-10-31 10:01:47
 */
@Slf4j
@Service
public class UserDetailsServiceImpl extends ServiceImpl<UserDetailsMapper, UserDetails> implements UserDetailsService {
    @Resource
    private UserDetailsMapper userDetailsMapper;

    @Resource
    private UserMapper userMapper;

    /**
     * @return
     * @Author zgc
     * @Description
     * @Param params
     * @Result
     * result == 0：认证通过，身份证和姓名信息匹配。
     * result == 1000：认证失败，身份证号码和姓名不匹配。
     **/
    @Override
    @Transactional
    public Boolean realNameUser(UserDetails userDetails) throws TencentCloudSDKException {
//        //用户实名认证
//        IdCardVerificationRequest idCardVerificationRequest = new IdCardVerificationRequest();
//        idCardVerificationRequest.setIdCard(userDetails.getIdNumber());
//        idCardVerificationRequest.setName(userDetails.getName());
//        //检查身份证和姓名是否匹配
//        IdCardVerificationResponse idCardVerificationResponse = faceidClient.IdCardVerification(idCardVerificationRequest);
//        if(!CheckEmptyUtil.isEmpty(idCardVerificationResponse)){
//             if(idCardVerificationResponse.getResult().equals("0")){
//                 log.info("用户:[{}],实名认证通过", userDetails.getId());
//                 //实名通过后将实名信息存入
//                 userDetailsMapper.insert(userDetails);
//                 //将用户表中的用户状态改为已实名
//                 User user = new User();
//                 user.setId(userDetails.getUserId());
//                 user.setIsAuth("1");
//                 userMapper.updateById(user);
//                 return true;
//             }
//            else {
//                log.info("认证失败，身份证号码和姓名不匹配");
//                throw new SxkfException(500,"认证失败，身份证号码和姓名不匹配");
//            }
//        }
//        return false;
        throw new SxkfException("暂未完成");
    }

}
